//
//  MessageStoreView.m
//  Experss
//
//  Created by 嗯，大葱 on 17/8/4.
//  Copyright © 2017年 嗯，大葱. All rights reserved.
//

#import "MessageStoreView.h"
#import "MessageStoreViewCell.h"
#import "MessageStoreTwoViewCell.h"
#import "HYBStarEvaluationView.h"//星级


@implementation MessageStoreView
{
    NSString *phoeS;
    NSString *addressS;
    NSString *timeS;
    NSString *scoreS;
    NSString *pingjiaS;
    
    HYBStarEvaluationView *starViewUnClick;
}
- (void)getDataFormController:(NSDictionary *)dic {
    phoeS = dic[@"tel"];
    addressS = dic[@"address"];
    timeS = dic[@"addtime"];
    scoreS = dic[@"praise_level"];
    pingjiaS = dic[@"desc"];
    [self.tableView reloadData];
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        phoeS = @"";
        addressS = @"";
        timeS = @"";
        scoreS = @"";
        pingjiaS = @"";
          [self configureView];
        
    }
    return self;
}

- (void)setContentArry:(NSArray *)contentArry {
    _contentArry = contentArry;
   
}
- (void)configureView {

    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kView_Width, kView_Height) style:(UITableViewStylePlain)];
    _tableView.backgroundColor = KShouYeBg;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    _tableView.showsVerticalScrollIndicator = NO;
    _tableView.showsHorizontalScrollIndicator = NO;
    _tableView.separatorStyle = kSpNone;

    [self addSubview:_tableView];
    [_tableView registerNib:[UINib nibWithNibName:@"MessageStoreViewCell" bundle:nil] forCellReuseIdentifier:@"MessageStoreViewCell"];
     [_tableView registerNib:[UINib nibWithNibName:@"MessageStoreTwoViewCell" bundle:nil] forCellReuseIdentifier:@"MessageStoreTwoViewCell"];
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 3;
    }else {
        return 1;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 2) {
        self.tableView.rowHeight = UITableViewAutomaticDimension;
        self.tableView.estimatedRowHeight = 240;
        return self.tableView.rowHeight;
    }else {
        return 50;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 10;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *V = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kView_Width, 10)];
    V.backgroundColor = KShouYeBg;
    return V;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 2) {
        MessageStoreTwoViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MessageStoreTwoViewCell"];
        cell.selectionStyle = kSeNone;
        cell.textV.text = pingjiaS;
        return cell;
    }else {
        MessageStoreViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MessageStoreViewCell"];
        cell.selectionStyle = kSeNone;
        if (indexPath.section == 0) {
            NSArray *titleArr = @[@"电        话",@"地        址",@"开店时间"];
            cell.titlLB.text = titleArr[indexPath.row];
            
            NSString *conStr;
            if (indexPath.row == 0) {
                conStr = phoeS;
            }
            if (indexPath.row == 1) {
                conStr = addressS;
            }
            if (indexPath.row == 2) {
                conStr = timeS;
            }
            
            cell.contLB.text = conStr;
        }
        
    
        if (indexPath.section == 1) {
            cell.titlLB.text = @"综合评分";
            cell.bgV.hidden = NO;
            cell.scoreLB.text = scoreS;
            if (starViewUnClick) {
                [starViewUnClick removeFromSuperview];
            }
            //星级＝＝＝显示的星星数是:  全部星星(星星总数)／fullScore = 要显示的星星数
            starViewUnClick = [[HYBStarEvaluationView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(cell.scoreLB.frame)+15, 5, 100, 20) numberOfStars:5 isVariable:NO];
            starViewUnClick.actualScore =[scoreS floatValue];
            starViewUnClick.fullScore = 5;
            starViewUnClick.isContrainsHalfStar = YES;
            
            [cell.bgV addSubview:starViewUnClick];
            
            
            
        }
        
          return cell;
    }
    
   
    
  
}














@end
